package libaryinterface;

import jdbc.DeleteJdbc;
import jdbc.Insertjdbc;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: YKH
 * Date: 2022-05-14
 * Time: 20:27
 * author:DeleteInterface
 */
public class DeleteInterface extends JFrame {

    public DeleteInterface() throws FontFormatException {
        //设置窗口
        super("删除界面");


        //创建书名标签
        JLabel label = new JLabel("书名:");
        label.setBounds(200,150,100,40);

        //设置标签字体
        Font font = new Font("黑体", Font.BOLD, 20);
        label.setFont(font );

        //创建文本框
        JTextField textField = new JTextField();
        textField.setBounds(300,150,300,40);
        textField.setFont(font);

        //创建删除按钮
        JButton button = new JButton("删除");
        button.setBounds(400,200,80,30);
        button.setFont(font);
        //设置监听
        button.addActionListener(new ActionListener() {
            boolean flag;
            @Override
            public void actionPerformed(ActionEvent e) {
                String name = textField.getText();
                try {
                    DeleteJdbc deleteJdbc = new DeleteJdbc();
                    flag = deleteJdbc.delete (name);
                } catch (SQLException ex) {
                    throw new RuntimeException(ex);
                }
                //弹窗
                if( flag ){
                    new MyDialogDemo("删除成功!");
                }
                else {
                    new MyDialogDemo("要删除的书籍不存在!");
                }
            }
        });

        //获得容器
        Container container = this.getContentPane();
        container.setBackground(new Color(50, 144, 236));
        setBounds(200,200,800,600);
        setLayout(null);
        setVisible(true);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);

        //添加
        container.add(label);
        container.add(textField);
        container.add(button);
    }
}
